/**
 * 2024/01/01 - 2024/12/31
 **/
package com.snail.camunda.engin.process.holder;

import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author: (zg)
 * @Date: 2024/12/16 11:27
 * @Version: 1.0.0
 */
@Component
public class RuntimeHolder {

    @Resource
    RuntimeService runtimeService;

    public String startProcessInstanceById(String processId) {
        ProcessInstance instance = runtimeService.startProcessInstanceById(processId);
        return instance.getProcessDefinitionId();
    }

    public boolean deleteProcessInstance(String processId, String deleteReason) {
        runtimeService.deleteProcessInstance(processId, deleteReason);
        return true;
    }

    public Object getVariable(String executionId, String variableName) {
        return runtimeService.getVariable(executionId, variableName);
    }

    public String getVariableString(String executionId, String variableName) {
        Object variable = runtimeService.getVariable(executionId, variableName);
        if(null == variable){
            return "";
        }
        return variable.toString();
    }

}